package com.kgc.scd.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.bean.Order;
import com.kgc.scd.bean.OrderVO;
import com.kgc.scd.service.OrderServiceFeign;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: WangKuoKuo
 * @create: 2022-06-14 15:37
 * @description:
 **/

@RestController
@Api(tags = "21、订单中心")
public class OrderWebController {
    @Autowired
    private OrderServiceFeign orderServiceFeign;

    /**
     * @param : [orderId]
     * @return : com.kgc.scd.util.RequestResult<java.util.List<com.kgc.scd.bean.OrderVO>>
     * @author : WangKuoKuo
     * @date : 2022/6/14/014
     * @description : 查询订单详情
     */
    @GetMapping ("/queryOrderList")
    @ApiOperation("根据订单id查询订单")
    RequestResult<List<OrderVO>> queryOrderList(@RequestParam("orderId") String orderId) {
        return orderServiceFeign.queryOrderList(orderId);
    }

    /**
     * @param : [orderId]
     * @return : com.kgc.scd.util.RequestResult<java.lang.String>
     * @author : WangKuoKuo
     * @date : 2022/6/14/014
     * @description : 删除订单
     */
    @PostMapping("/delOderByOrderId")
    @ApiOperation("删除订单,order_state等于3才可以删")
    public RequestResult<Map<String, Object>> delOderByOrderId(@RequestParam String orderId) {
        return orderServiceFeign.delOderByOrderId(orderId);
    }

    @GetMapping("/queryOderByOrderState")
    @ApiOperation("根据订单状态查询订单")
    @RequestPermission
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderState", value = " 订单状态(0:未支付 1:未发货 2:已发货 3：已签收)"),
            @ApiImplicitParam(name = "pageSize", value = " 每页容量"),
            @ApiImplicitParam(name = "pageNo", value = " 页码"),
            @ApiImplicitParam(name = "orderBy", defaultValue = "1",value = "1：根据时间升序 0：根据时间降序")
    })

    public RequestResult<PageSupport<Order>> queryOderByOrderState(@RequestUser UserAnno userAnno,
                                                                   @RequestParam(value = "orderState", required = false) Integer orderState,
                                                                   @RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize,
                                                                   @RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                                                                   @RequestParam(value = "orderBy",defaultValue = "1")Integer order) {
        return orderServiceFeign.queryOderByOrderState(userAnno.getUserId(), orderState,pageSize,pageNo,order);
    }


}
